<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>水平对齐</title>
  <style type="text/css">
    .container{
      border: 1px solid #ccc;
      margin: 10px;
      padding: 10px;
    }
    .item{
      background-color: #ccc;
    }
    .container-1{
    }
    .container-2 .item{
      width: 500px;
    }
    .container-3{
      position: relative;
      height: 100px;
    }
    .container-3 .item{
      width: 300px;
      height: 100px;
      position: absolute;

    }
  </style>
</head>
<body>
  <div class="container container-1">
    <span>一段文字</span>
  </div>
  <div class="container container-2">
    <div class="item">this is block item</div>
  </div>
  <div class="container container-3">
    <div class="item">this is absolute item</div>
  </div>
  
  <h3>水平居中</h3>
  <ul>
    <li>inline 元素: text-align: center</li>
    <li>block 元素: margin: auto</li>
    <li>absolute 元素: left:50% + margin-left 负值</li>
  </ul>
  <h3>垂直居中</h3>
    <li>inline 元素: line-height 的值等于 height 值</li>
    <li>absolute 元素: top: 50% + margin-top 负值</li>
    <li>absolute 元素: transform(-50%, -50%)</li>
    <li>absolute 元素: top, left, bottom, right = 0 + margin: auto</li>
  <ul></ul>
</body>
</html>